package com.googlecode.ebasys.entity;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

/**
 * Base class for persistent entities of EBASYS platform. It provides ID fields
 * with getters and setters. Extend this class and mark subclass as 
 * {@link Entity}.
 *
 * @author Tomas Varaneckas
 * @version $Id: PersistentEntity.java 58 2009-01-22 20:49:29Z tomas.varaneckas $
 */
@SuppressWarnings("serial")
@MappedSuperclass
public abstract class PersistentEntity implements Serializable {

    /**
     * Auto-generated identity field
     */
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    protected Long id;

    /**
     * Gets the ID
     * 
     * @return ID
     */
    public Long getId() {
        return id;
    }

    /**
     * Sets the ID
     * 
     * @param id ID to set
     */
    public void setId(final Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        return result;
    }

    @Override
    public boolean equals(final Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        PersistentEntity other = (PersistentEntity) obj;
        if (id == null) {
            if (other.id != null)
                return false;
        } else if (!id.equals(other.id))
            return false;
        return true;
    }

}